import requests
from work.commom.OperateMysql import OperateMysql

# res = []
# for i in range(201500001, 201501000):
#     dict_t = {"deviceId": str(i), "childDeviceIds": ["1", "2", "3"]}
#     res.append(dict_t)
#
# json_data = {
#     "bind": True,
#     "configType": 1,
#     "configId": "91489563578466304",
#     "infos": res
# }
# requests.post(url='http://10.0.17.17:3333/IotService/schemeConfig/deviceBind/v1', json=json_data)


# 批量添加自动任务
# for i in range(1, 101):
#     json_data = {
#         "acquisitionName": f"测试采集配置方案0928_{i}",
#         "acquisitionCode": f"test0928_{i}",
#         "acquisitionPeriod": "0 0/5 * * * ?",
#         "businessCode": "62001002",
#         "priority": 1,
#         "enableConfig": 0,
#         "remark": f"test_{i}"
#     }
#     requests.post(url='http://10.0.17.17:3333/IotService/acquisitionConfigScheme/addAcquisitionConfigScheme/v1',
#                   json=json_data)


# 批量添加任务参数
sql = """select acquisition_id from acquisition_config_scheme where acquisition_code like 'test0928%' """
res = OperateMysql(database='iot_center').excute_sql(sql)
# print(res)
res_list = []
for i in res:
    for j in i:
        res_list.append(j)
# print(res_list)
# for i in res_list:
#     post_dict = [
#         {"compensateAcquisitionId": i,
#          "paramCode": "f1",
#          "paramValue": "1",
#          "showType": "int",
#          "remark": "test"}
#     ]
#     requests.post(url='http://10.0.17.17:3333/IotService/compensateAcquisitionParam/saveCompensateAcquisitionParam/v1',
#                   json=post_dict)


# 批量添加任务对应设备
j = 202400001
for i in res_list:
    infos = []
    for k in range(100):
        info_dict = {
            "deviceId": str(j + k),
            "childDeviceIds": ["1", "2", "3"]
        }
        infos.append(info_dict)
    post_data = {
        "bind": True,
        "configType": 1,
        "configId": i,
        "infos": infos
    }
    requests.post(url='http://10.0.17.17:3333/IotService/schemeConfig/deviceBind/v1', json=post_data)
    j += 100
